package com.weavernorth.action.AssistantReport;

import com.weavernorth.sysap.dao.SyncOrgStrucDaoImpl;
import org.apache.commons.logging.Log;


import weaver.conn.RecordSet;
import weaver.formmode.setup.ModeRightInfo;
import weaver.general.Util;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

import java.util.UUID;

public class HandlerReport implements Action {
    private static Log log = org.apache.commons.logging.LogFactory.getLog(HandlerReport.class.getName());
    @Override
    public String execute(RequestInfo requestInfo) {
        RecordSet rsSql = new RecordSet();
        RecordSet rsUpdateFw = new RecordSet();
        RecordSet rs = new RecordSet();
        RecordSet rsJs = new RecordSet();
        log.info("逻辑开始");

        //1：获取表单的requestid
        String strRequestId = requestInfo.getRequestid();
        log.info("表单requestid"+strRequestId);
        //2：获取表单名称tablename
        String strTablename = requestInfo.getRequestManager().getBillTableName();
        log.info("表单名称："+strTablename);
        //查询表单数据的sql
        String strSql = "select *   from  "+strTablename+" f,"+strTablename+"_dt1  d  where  d.mainid=f.id  and  f.requestid = '"+strRequestId+"'";
        log.info("查询表单主表、明细数据的sql:"+strSql);
        rsSql.executeQuery(strSql);
        //流程可能含有多个明细表
        while(rsSql.next()){
            //获取姓名字段值
            String strXm = Util.null2String(rsSql.getString("xm") );
            log.info("姓名："+strXm);
            //获取分公司的值
            String  strFgs = Util.null2String(rsSql.getString("fgs"));
            log.info("分公司："+strFgs);
            //获取评分期间的值
            String  strPfqj = Util.null2String(rsSql.getString("pfqj"));
            log.info("评分期间："+strPfqj);

            //获取奖金金额
            //查询奖金基数
            String strJsSql = "select qyjljs from uf_jjjspzb where  fgs = '"+strFgs+"'";
            rsJs.executeQuery(strJsSql);
            String strJs="0.0";
            if(rsJs.next()){
                //获取奖金基数
                strJs = Util.null2String(rsJs.getString("qyjljs"));
            }
            //查询建模表
            String strQyjl = "select zdf from uf_qyjlpfhzb where xm = '"+strXm+"'  and  pfqj = '"+strPfqj+"'  and  fgs = '"+strFgs+"'";
            rs.executeQuery(strQyjl);
            String strZdf = "";
            if(rs.next()){
                strZdf=rs.getString("zdf");
            }
            //获取奖金金额
            double intDf = Integer.parseInt(strZdf);
            double dubJj = (intDf / 100) * Double.parseDouble(strJs);
            double dubDev = (double) Math.round(dubJj*100) / 100;

                    String strUpdateAstat = "update uf_qyjlpfhzb set  jjje = '"+dubDev+"'  where fgs = '"+strFgs+"' and  xm = '"+strXm+"' nad  pfqj='"+strPfqj+"'";
                    log.info("更新此人数据的sql:"+strUpdateAstat);
                    rsUpdateFw.executeQuery(strUpdateAstat);

        }
        log.info("逻辑结束");
        return SUCCESS;
    }
}
